<?php

namespace app\model\zs;

use think\Model;

class ZsTwShopOrder extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'tw_shop_order';

    // 设置当前模型的数据库连接
    protected $connection = 'zs';

    // 自动写入时间的类型
    protected $autoWriteTimestamp = 'datetime';

    // 定义时间戳字段名
    protected $createTime = 'create_at';
    protected $updateTime = 'update_at';

    const PAYMENT_TYPE_WX = 1;
    const PAYMENT_TYPE_ONE = 2;

    const DELETED_ON = 1;
    const DELETED_OFF = 0;

    const EAT_OUT_ON = 1;
    const EAT_OUT_OFF = 0;

    const FETCH_SF = 1;
    const FETCH_SELF = 2;

    public function orderItems()
    {
        return $this->hasMany(ZsTwShopOrderItem::class, 'order_no', 'order_no')->where('status', 1)->where('deleted', 0);
    }

    public function businessModel()
    {
        return $this->belongsTo(ZsBusiness::class, 'bid', 'id');
    }

    public function orderSend()
    {
        return $this->hasOne(ZsTwShopOrderSend::class, 'order_no', 'order_no')->where('status', 1)->where('deleted', 0);
    }

    /**
     * 取餐方式（后台订单筛选显示）
     *
     * @return array
     */
    public static function fetchRels()
    {
        return [
            self::FETCH_SF => '同城配送',
            self::FETCH_SELF => '自提',
        ];
    }

    /**
     * 取餐方式（小程序订单显示）
     *
     * @return array
     */
    public static function fetchRelsMini()
    {
        return [
            self::FETCH_SF => '同城配送',
            self::FETCH_SELF => '自提',
        ];
    }

    // `tw_shop_order`.`status` '订单状态(0已取消,1预订单,2待支付,3待发货,4待签收,5已完成,6待接单,7已通知快递,8取消通知快递,9顺丰原因取消,10骑士撤单,11配送员异常上报,12订单退款)'
    // 订单状态流转：
    // 1=>2->(6)->3->7->4->5
    public static function statusRels()
    {
        return [
            0 => '已取消',
            1 => '待支付',
            2 => '待支付',
            3 => '待发货',
            4 => '待收货',
            5 => '已签收',
            6 => '待接单',
            7 => '等待配送',
            8 => '取消配送',
            9 => '顺丰原因取消',
            10 => '骑士撤单',
            11 => '配送员异常上报',
            12 => '订单退款',
            13 => '退单',
        ];
    }

    public static function statusRelsForAdmin()
    {
        return [
            3 => '待发货',
            4 => '待收货',
            5 => '已签收',
            6 => '待接单',
            7 => '等待配送',
            8 => '取消配送',
            9 => '顺丰原因取消',
            10 => '骑士撤单',
            11 => '骑士异常上报',
            12 => '订单退款',
            13 => '退单',
        ];
    }

    public static function statusClassRelsForAdmin()
    {
        return [
            3 => 'layui-bg-red',
            4 => 'layui-bg-blue',
            5 => 'layui-bg-green',
            6 => 'layui-bg-orange',
            7 => 'layui-bg-orange',
            8 => 'layui-bg-black',
            9 => 'layui-bg-black',
            10 => 'layui-bg-black',
            11 => 'layui-bg-black',
            12 => 'layui-bg-red',
            13 => 'layui-bg-red',
        ];
    }

    /**
     * 1卡、商户端小程序用
     */
    public static function statusRelsForStore()
    {
        return [
            3 => '已接单',
            4 => '快递运输中',
            5 => '已签收',
            6 => '等待接单',
            7 => '已通知快递',
            8 => '取消通知',
            9 => '顺丰原因取消',
            10 => '骑士撤单',
            11 => '配送员异常上报',
            12 => '订单退款',
        ];
    }

    /**
     * 所有已支付的状态
     */
    public static function statusRelsPayed()
    {
        return [
            3,
            4,
            5,
            6,
            7,
            8,
            9,
            10,
            11,
        ];
    }

    /**
     * 商户端小程序用
     */
    public static function statusClassRelsForStore()
    {
        return [
            0 => '',
            1 => 'u-type-error-dark',
            2 => 'u-type-error-dark',
            3 => 'u-type-warning',
            4 => 'u-type-warning',
            5 => 'u-type-success-dark',
            6 => 'u-type-primary-dark',
            7 => 'u-type-warning',
            8 => 'u-type-warning',
            9 => 'u-type-warning',
            10 => 'u-type-warning',
            11 => 'u-type-warning',
            12 => 'u-type-error-dark',
        ];
    }

    public static function statusClassRels()
    {
        return [
            0 => '',
            1 => 'u-type-error-dark',
            2 => 'u-type-error-dark',
            3 => 'u-type-warning',
            4 => 'u-type-warning',
            5 => 'u-type-success-dark',
            6 => 'u-type-primary-dark',
            7 => 'u-type-warning',
            8 => 'u-type-warning',
            9 => 'u-type-warning',
            10 => 'u-type-warning',
            11 => 'u-type-warning',
            12 => 'u-type-error-dark',
        ];
    }

    public static function paymentTypeRels()
    {
        return [
            self::PAYMENT_TYPE_WX => '微信支付',
            self::PAYMENT_TYPE_ONE => '余额支付',
        ];
    }

    public static function paymentTypeRelsSim()
    {
        return [
            self::PAYMENT_TYPE_WX => '微信',
            self::PAYMENT_TYPE_ONE => '余额',
        ];
    }
}
